{% extends 'front/index_products/base_index_products.html' %}

{% block title %}购物车{% endblock %}

{% block css %}
    {{ super() }}
    <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/buy.css') }}">
{% endblock %}

{% block main %}
    <div class="container">
        <div class="">
            {% if books %}
                <div class="row clearfix">
                    <div class="col-md-12 column">
                    </div>
                    <div class="col-md-12 column">
                        <div class="cart_title"><h3>我的购物车</h3></div>
                        {% for message in get_flashed_messages() %}
                            <div class="alert alert-warning text-center"><b>{{ message }}</b></div>
                        {% endfor %}
                        <table class="table table-hover" id="table">
                            <thead>
                            <tr>
                                <th><input type="checkbox" class="checkOnly" name="checkbox_v1" value="version1"
                                           onclick="allSelect('checkbox_v1', 'checkbox1')"><span> 全选</span></th>
                                <th class="content">
                                    商品名称
                                </th>
                                <th class="content">
                                    单价
                                </th>
                                <th class="content">
                                    数量
                                </th>
                                <th class="content">
                                    总价
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            {% for book in books %}
                                <tr>
                                    <td>
                                        <div>
                                            <input class="dan_select check" type="checkbox" name="checkbox1"
                                                   value="layer1"
                                                   onclick="singleSelect2parent('checkbox_v1', 'checkbox1')">
                                            <input type="hidden" name="book_id" value={{ book['_id'] }}>
                                            {% if book.is_off_shelf %}
                                                <span class="danger">已下架</span>
                                            {% endif %}
                                        </div>
                                    </td>
                                    <td>
                                        <div class="book_img left"><img src={{ book['img_url'] }}></div>
                                        <div class="title">
                                            {% if book.is_off_shelf %}
                                                <h3 class="danger">已下架</h3>
                                                <span>{{ book.title }}</span>
                                            {% else %}
                                                <a href="{{ url_for('products.product', id=book['_id']) }}">{{ book.title }}</a>
                                            {% endif %}
                                        </div>
                                    </td>
                                    <td>
                                        <span class="price">{{ book.price }}</span><span>￥</span>
                                    </td>
                                    <td class="content">
                                        <span>
                                             <input type="button" value="-" class="reduces">
                                             <span class="span"> {{ book.book_num }} </span>
                                             <input type="button" value="+" class="adds">
                                             <input type="hidden" name="book_id" value={{ book['_id'] }}>
                                        </span>
                                    </td>
                                    <td>
                                        <span class="prices">{{ book.sum_price }}</span><span>￥</span>
                                    </td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
                <a href="#" class="btn button btn-danger delete-book" type="button">删除</a>
                <div class="to_pay right">
                    <div>
                        <span class="sum_books">共<span id="count">0</span>件商品</span>
                        <span>总金额：</span>
                        <span class="sum_mon">0</span>￥
                        {#                <span class="con_mon">0</span><span>（含运费元）</span>#}
                    </div>
                    <br>
                    <div class="btn pay_btn right"><a href="#" type="button" onclick="to_buy()">结算</a></div>
                </div>
            {% else %}
                <hr>
                <div class="recommend_book text-center col-md-2" ng-controller="recommend_cart">
                    <div class="text-center"><p>为你推荐</p></div>
                    <ul>
                        <li ng-repeat="book in recommend_cart">
                            <a href="/product%3F{{ '{{book.id}}' }}">
                                <img src="{{ '{{book.img}}' }}" title="{{ '{{book.title}}' }}"
                                     alt="{{ '{{book.title}}' }}">
                                <p>{{ '{{book.title}}' }}</p>
                                <p>{{ '{{book.author}}' }}</p>
                            </a>
                            <hr>
                        </li>
                    </ul>
                </div>
                <div class="col-md-offset-3">
                    <tr>
                        <td>
                            <div class="cart_em left">
                                <h3 class="left">您的购物车为空！</h3>
                                <div class="to_products  btn">
                                    <a type="button" href="{{ url_for('products.index') }}">去添加购物</a>
                                </div>
                            </div>
                        </td>
                    </tr>
                </div>
            {% endif %}
        </div>
        <div class="col-md-12">
            <hr>
        </div>
    </div>
{% endblock %}

{% block js %}
    {{ super() }}
    <script type="text/javascript" src="{{ url_for('static', filename='js/cart.js') }}"></script>
{% endblock %}